<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ include file="../../attr.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=emulateIE7"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" href="${ctx}/css/sapar.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/kkpager_blue.css"/>
    <link href="${ctx}/css/select2.min.css" rel="stylesheet" />


    <style type="text/css">
        td {
            text-align: center;
        }
    </style>
</head>
<body>
<div class="tab-content-item">

    <audio src="../../audio/Beep_Short.mp3" id="audio"></audio><!-- 成功提示音 -->
    <audio src="../../audio/Alarm_Clock (1).mp3" id="audio1"></audio><!-- 失败提示音 -->
        <div class="kv-item clearfix">


            <div class="kv-item clearfix">
                <%--<div class="kv-item-content">--%>
                    <%--<label><span class="impInfo">*</span>科室：</label>--%>
                    <%--<span>手术室</span>--%>
                    <%--<select id="packageDepartid" name="packageDepartid" onChange="showPack(true)">--%>
                        <%--<c:if test="${deptList !=null}">--%>
                            <%--<option value="0">请选择科室</option>--%>
                            <%--<c:forEach items="${deptList }" var="deptment">--%>
                                <%--<option  <c:if test="${selected==deptment.departmentId}">selected</c:if>  value="${deptment.departmentId}">${deptment.departmentName}</option>--%>
                            <%--</c:forEach>--%>
                        <%--</c:if>--%>
                    <%--</select>--%>
                <%--</div>--%>
                <div class="kv-item-content">
                    <label>录入人：</label>
                    <div class="kv-item-content" style="line-height:30px;">
                        <input style="width: 100px" name="huishouren" id="huishouren" class="gui-input" placeholder="录入人" type="text" value="">
                    </div>
                </div>
                <div class="kv-item-content" style="padding-left: 200px">
                    <a   href="javascript:;" class="sapar-btn sapar-btn-recom query-btn" id="baocun"
                        onclick="do_save()">保存</a>
                </div>
            </div>

            <div class="kv-item-content" id="app">
                <%--<label>网篮条码：</label>--%>
                <%--<div style="width: 216px" class="kv-item-content">--%>
                    <%--<input  type="text" maxLength="7" v-model=huishouWanglanTiaoma name="huishouWanglanTiaoma" id="wanglantiaoma"--%>
                           <%--placeholder="网篮条码" autofocus="autofocus" @keyup.enter="enterFun" >--%>
                <%--</div>--%>
                <%--<label>网篮名称：</label>--%>
                <%--<div class="kv-item-content">--%>
                    <%--<input type="text" v-model="huishouWanglanMingcheng" name="huishouWanglanMingcheng" placeholder="网篮名称"--%>
                           <%--readonly="readonly" id="wanglanMingcheng">--%>
                <%--</div>--%>

            </div>
        </div>
        <form class="package">
        <div class="table">
            <!--表格具体内容-->
            <div class="table-box">
                <table id="tbpck">
                    <thead>
                    <tr>
                        <th>部门</th>
                        <th>包名</th>
                        <th>数量</th>
                    </tr>
                    </thead>
                    <tbody id="body_list">

                    <c:if test="${packages !=null}">
                        <c:forEach items="${packages }" var="packages">
                            <tr>
                                <td><input type="hidden" name="depId" value="${packages.packageDepartid}"/>${packages.tbDepartment.departmentName}</td>
                            <td><input type="hidden" name="packageId" value="${packages.packageId}"/>${packages.packageName}</td>
                            <td><input style="text-align: center" type="text" name="packageNum"/></td>
                            </tr>
                        </c:forEach>
                    </c:if>
                    </tbody>
                </table>
            </div>
            <%--<div>--%>
                <%--<input id="leftPage" class="butLeft" type="button" value="上一页"/>--%>
                <%--<input id="rightPage" class="butRight" type="button" value="下一页"/>--%>
                <%--<span>到第&nbsp;</span><input id="goPage" class="textBox" type="text" value="1"/><span--%>
                    <%--style="margin-left: 4px;">页&nbsp;</span>--%>
                <%--<input id="sureBut" class="sure" type="button" value="确定"/>--%>
                <%--<span>共</span><span class="totalPages" id="totalNum">0</span><span>&nbsp;页</span>--%>
            <%--</div>--%>
        </div>
        </form>
</div>

</body>
<script type="text/javascript" src="${ctx}/js/jquery.js"></script>
<script type="text/javascript" src="${ctx}/js/vue.min.js"></script>
<script type="text/javascript" src="${ctx}/js/kkpager.min.js"></script>
<%@ include file="../../js.jsp" %>
<script type="text/javascript">

//    window.onload = function () {
//        $("#wanglantiaoma").focus();
//    };
    <%--var data = ${packages};--%>
    <%--shuzi(data);--%>
    $(function () {

//        $('select').select2();

        $("#back").click(function () {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        });
        $("#save").click(function () {
            do_save();
        });

//        $(document).keydown(function (event) {
//            var oPlay0 = document.getElementById("audio");
//            var oPlay1 = document.getElementById("audio1");
//            var packageName = $("input[name='packageName']").val();
//            if (event.keyCode == 13) {
//                debugger
//                if ($("#packageName").is(":focus") ) {
//                    showPack(false);
//                    $("#wanglantiaoma").focus();
//                }
//            }
//        });


    });
//
//    var oPlay0 = document.getElementById("audio");
//    var oPlay1 = document.getElementById("audio1");
//
//    var vm = new Vue({
//        el:'#app',
//        data : {
//            huishouWanglanTiaoma: '',
//            huishouWanglanMingcheng: '',
//        },
//        methods : {
//            enterFun: function () {
//                var that = this;
//                if ($("#wanglantiaoma").is(":focus") && !isNullOrEmpty(that.huishouWanglanTiaoma)) {
//                    $.get("/wutiaoma/findwanglan.do?huishouWanglanTiaoma=" + that.huishouWanglanTiaoma,function(data){
//                        if (data.status == true) {
//                            oPlay0.play();
//                            that.huishouWanglanMingcheng = data.zsWanglan.wlMingcheng;
//                            that.addpackage();
//                        }else if (data.status == false) {
//                            oPlay1.play();
//                            that.huishouWanglanTiaoma = "";
//                            that.huishouWanglanMingcheng = "";
//                        }
//                    })
//
//                }
//
//
//            },
//        }
//    })


    <%--function showPack(data) {--%>
        <%--if(data==true){--%>
            <%--$("#packageName").val("");--%>
        <%--}--%>
        <%--$("#packageName").focus();--%>
        <%--var url = "${ctx}/wutiaoma/findHuishouPackageByDepart.do?packageCode=" + $("#packageName").val() + "&packageDepartid=" + $("#packageDepartid").val();--%>
        <%--$.ajax({--%>
            <%--type: "POST",--%>
            <%--url: url,--%>
            <%--data: $('#dataHuiShouForm').serialize(),// 你的formid--%>
            <%--error: function (request) {--%>
                <%--layer.alert("网络故障，请稍后再试!");--%>
            <%--},--%>
            <%--success: function (datas) {--%>
                <%--if (datas.status == "true") {--%>
                    <%--var data = datas.packages;--%>
                    <%--shuzi(data);--%>


                <%--}--%>
            <%--}--%>
        <%--});--%>
    <%--}--%>

//    function shuzi(data){
//        $("#tbpck tbody").empty();
//        var str = "";
//        for (var i = 0; i < data.length; i++) {
//            var dep = data[i].tbDepartment;
//            var deptname;
//            if (dep != null) {
//                deptname = dep.departmentName;
//            } else {
//                deptname = "";
//            }
//            str += '<tr><td>' + deptname + '</td><td class="text-left">' + data[i].packageName + '</td><td><input type="hidden" name="deptName" value="' + deptname + '"/><input type="hidden" name="pid" value="' + data[i].packageId + '"/><input style="text-align:center" type="text" name="key" maxlength="3" onkeyup="this.value=this.value.replace(/\\D/g,\'\')" class="gui-input"/><input type="hidden" name="pname" value="' + data[i].packageName + '"/></td></tr>'
//        }
//        $("#tbpck tbody").append(str);
//    }


    function do_save() {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        var rtnJson = new Array();
        var huishouren = $("#huishouren").val();
        var check = true;
        $('input[name="packageNum"]').each(function () {
            var depId = $(this).parent().prev().prev().find("input[name='depId']").val();
            var id = $(this).parent().prev().find("input[name='packageId']").val();
            var val = $(this).val();
            if (val != '') {
                var obj = new Object();
//                obj.keshi_packId = keshi+id;
//                obj.keshi = keshi;
//                obj.keshiName = keshiName;
                obj.packId = id;
                obj.packageNum = val;
                obj.depId  = depId;
//                obj.packNum = val;
//                obj.depId = depId;
//                obj.depVal = depVal;
//                obj.huishouWanglanTiaoma = huishouWanglanTiaoma;
//                obj.huishouWanglanMingcheng = huishouWanglanMingcheng;
                rtnJson.push(obj);
                //console.log(rtnJson);
            }
        });
        if(rtnJson.length!=0){
            showMask();
            $.ajax({
                type: "POST",
                url: "${ctx}/wutiaoma/peibaoSave",
                data: {"data":JSON.stringify(rtnJson),"huishouren":huishouren},// 你的formid
                error: function (request) {
                    layer.alert("失败!");
                },
                success: function (data) {
                    $(".query-btn").css("opacity", "1");
                    $("#mask").hide();
                    if (data.status == "true") {
                        parent.callbackData();
                        parent.layer.close(index);
                    } else {
                        layer.alert(data.msg);
                    }
                }
            });
        }

    }



    //判断是否为空
    function isNullOrEmpty(strVal) {
        if (strVal != null) {
            strVal = strVal.replace(/(^\s*)|(\s*$)/g, "");
        }
        if (strVal == '' || strVal == null || strVal == undefined) {
            return true;
        } else {
            return false;
        }
    }

document.onkeydown = function (event) {
    var e = event || window.event || arguments.callee.caller.arguments[0];
    var oPlay0 = document.getElementById("audio");
    var oPlay1 = document.getElementById("audio1");

    if (e && e.keyCode == 13) { // enter 键
        var isFocus = $("#huishouren").is(":focus");
        var huishouren = $("#huishouren").val()
        if(isFocus&&huishouren!=null){
            do_save();
        }

    }
};

</script>
</html>